package utils
{
	import alternativa.gui.base.ActiveObject;
	import alternativa.gui.controls.text.Text;
	import alternativa.gui.data.DataProvider;
	import alternativa.gui.enum.Align;
	import alternativa.gui.theme.defaulttheme.container.panel.Panel;
	import alternativa.gui.theme.defaulttheme.controls.buttons.Button;
	import alternativa.gui.theme.defaulttheme.controls.buttons.CheckBox;
	import alternativa.gui.theme.defaulttheme.controls.dropDownList.DropDownList;
	import alternativa.gui.theme.defaulttheme.controls.text.Label;
	import alternativa.gui.theme.defaulttheme.controls.text.TextInput;
	import alternativa.gui.theme.defaulttheme.controls.tree.Tree;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.InteractiveObject;
	import flash.events.FocusEvent;
	import flash.filters.GlowFilter;
	
	import globals.Global;

	/**
	 * UI管理器
	 * @author XiLing
	 */
	public class UtilsUIManager
	{
		public static function createPanel(_parent:DisplayObjectContainer,_title:String='',_x:int=0,_y:int=0,_w:int=0,_h:int=0,_content:DisplayObject=null):Panel
		{
			var panel:Panel = new Panel();
			panel.width = _w;
			panel.height = _h;
			panel.x = _x;
			panel.y = _y;
			panel.title = _title;
			_parent.addChild(panel);
			if(_content)
			{
				panel.content = _content;
			}
			return panel;
		}
		
		public static function createTree(_parent:DisplayObjectContainer,_x:int,_y:int,_w:int,_h:int):Tree
		{
			var tree:Tree = new Tree();
			tree.width = _w;
			tree.height = _h;
			tree.x = _x;
			tree.y = _y;
			if(_parent)
				_parent.addChild(tree);
			return tree;
		}
		
		public static function createButton(_parent:DisplayObjectContainer,_label:String,_x:int,_y:int,_w:int,_h:int):Button
		{
			var button:Button = new Button();
			button.width = _w;
			button.height = _h;
			button.x = _x;
			button.y = _y;
			button.label = _label;
			_parent.addChild(button);
			return button;
		}
		
		public static function createLabel(_parent:DisplayObjectContainer,_label:String,_x:int,_y:int,_w:int=0,_h:int=0,_align:Align=null,_color:int=0x000000):Label
		{
			var label:Label = new Label();
			label.width = _w;
			label.height = _h;
			label.x = _x;
			label.y = _y;
			label.text = _label;
			label.color = _color;
			label.align = _align;
			if(_w==0)
				label.autosize=true;
			else
				label.autosize=false;
			_parent.addChild(label);
			return label;
		}
		
		public static function createTextInput(_parent:DisplayObjectContainer,_x:int,_y:int,_w:int,_h:int,_label:String="",maxChar:int=-1):TextInput
		{
			var textInput:TextInput = new TextInput();
			textInput.width = _w;
			textInput.height = _h;
			textInput.x = _x;
			textInput.y = _y;
			textInput.text = _label;
			if(maxChar>=0)
				textInput.maxChars = maxChar;
			_parent.addChild(textInput);
			return textInput;
		}
		
		public static function createDropdownList(_parent:DisplayObjectContainer,_listData:DataProvider,_x:int,_y:int,_w:int=0,_h:int=0):DropDownList
		{
			var dropDownList:DropDownList = new DropDownList();
			dropDownList.width = _w;
			dropDownList.height = _h;
			dropDownList.x = _x;
			dropDownList.y = _y;
			dropDownList.dataProvider = _listData;
			if(_parent)
				_parent.addChild(dropDownList);
			return dropDownList;				
		}
		
		public static function createCheckBox(_parent:DisplayObjectContainer,_label:String,_x:int,_y:int,_w:int=0,_h:int=0):CheckBox
		{
			var checkBox:CheckBox = new CheckBox();
			checkBox.width = _w;
			checkBox.height = _h;
			checkBox.x = _x;
			checkBox.y = _y;
			checkBox.label = _label;
			if(_parent)
				_parent.addChild(checkBox);
			return checkBox;				
		}
		
		/**
		 * 描边+抖动
		 * @param _checkDisplayObject
		 * @param _errorText
		 * @param _errorTextL
		 */
		public static function enableErrorByStyle1(_checkDisplayObject:DisplayObject,_errorTextL:Label,_errorText:String="",_enable:Boolean=true):void
		{
			if(_enable)
			{
				_checkDisplayObject.filters = [new GlowFilter(0xff0000)];
				_errorTextL.text = _errorText;
				if(_checkDisplayObject is TextInput)
				{
					changeFocusOn((_checkDisplayObject as TextInput).tf);
				}
			}
			else
			{
				_checkDisplayObject.filters = [];
				_errorTextL.text = "";
			}

		}
		
		public static function changeFocusOn(_toFocus:InteractiveObject):void
		{
			Global.stage.focus = _toFocus;
		}
	}
}